package com.example.demo.controller;


import com.example.demo.entity.Admin;
import com.example.demo.entity.Announcement;
import com.example.demo.service.IAdminService;
import com.example.demo.service.IAnnouncementService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 公告面板，发布通知 前端控制器
 * </p>
 *
 * @author hyb
 * @since 2024-12-24
 */
@RestController
@RequestMapping("/announcement")
public class AnnouncementController {
    @Autowired
    private IAnnouncementService iAnnouncementService; // 假设您有一个名为IAnnouncementService的服务接口

    // 处理GET请求，获取公告列表
    @GetMapping("/list")
    public List<Announcement> list() {
        return iAnnouncementService.list();
    }
    //根据id查询
    @GetMapping("/{id}")
    public Announcement getAnnouncementById(@PathVariable Integer id) {
        return iAnnouncementService.getById(id);
    }

    // 处理POST请求，创建新的公告
    @PostMapping("/create")
    public Announcement create(@RequestBody Announcement announcement) {
        iAnnouncementService.save(announcement);
        return announcement;
    }


}
